<template>
	<view class="wrap">
		<view class="header">
			<image :src="logoimg"></image>
		</view>
		<view class="content">
			<view>申请获取以下权限</view>
			<text>获得你的公开信息(昵称，头像、地区等)</text>
		</view>
		<view class="caoz">
			<button class="bottom2" @click="quxiao()">取消</button>
			<button class="bottom" type="primary" open-type="getUserInfo" withCredentials="true" lang="zh_CN"
				@getuserinfo="wxGetUserInfo">授权登录</button>
		</view>
		
	</view>
</template>

<script>
	import {
		gettoken,
	} from '@/api/login.js';
	var app = getApp();
	export default {
		data() {
			return {
				logoimg: app.globalData.app_logo,
				code: ''
			};
		},
		onLoad(options) {
			uni.setStorageSync('longing', true);
		},
		onShow() {

		},
		methods: {
			quxiao() {
				uni.navigateBack();
			},
			wxGetUserInfo() {
				var _this = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						_this.GetUserProfile(loginRes.code);
					},
				})
			},

			GetUserProfile(code) { // 微信QQ获取信息登陆
				let that = this;
				gettoken({
					data: {
						code: code,
						api: 'wxapp',
						parent_id: uni.getStorageSync('share_id') == '' ? 0 : uni.getStorageSync('share_id'),
					},
				}).then(res => {
					console.log(res);
					uni.hideLoading();
					uni.setStorageSync('token', res.data.token.token);
					uni.setStorageSync('member_id', res.data.token.uuid);
					// uni.setStorageSync('is_new_user', res.data.is_new_user)
					console.log('-------wx.login-------');
					if (res.code == 1) {
						uni.showToast({
							title: '登录成功！',
							icon: 'success'
						})
						setTimeout(() => {
							uni.navigateBack({

							})
						}, 2000)
					}
				});
			}
		}
	};
</script>

<style>
	.caoz {
		width: 100%;
		padding: 0 30upx;
		box-sizing: border-box;
		display: flex;
	}

	.wrap {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background: #fff;
		z-index: 200;
	}

	.content {
		text-align: center;
		background: #fff !important;
	}

	.header {
		text-align: center;
		height: 300rpx;
		line-height: 450rpx;
		background: #fff;
		justify-content: center;
	}

	.header image {
		width: 100rpx;
		height: 100rpx;
	}

	.content text {
		display: block;
		color: #9d9d9d;
		margin-top: 40rpx;
	}

	.bottom2 {
		border-radius: 80rpx;
		margin: 70rpx auto;
		font-size: 32rpx;
		width: 270upx;
		color: #ff6633;
	}

	.bottom2:after {
		border-radius: 100upx;
	}

	.bottom {
		border-radius: 80rpx;
		margin: 70rpx auto;
		font-size: 32rpx;
		width: 270upx;
		background: #ff6633;
	}

	.bottom::after {
		width: 200%;
		height: 200%;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 68rpx;
	}
</style>
